package main

import (
	"fmt"
	"net/rpc"
	"study.com/RPCandgRPC/rpc/model"

)

func main() {
	//连接服务端
	client, err := rpc.DialHTTP("tcp", "localhost:9000")
	if err != nil {
		//panic(err.Error())
		fmt.Println("rpc.DialHTTP error=", err)
		return
	}
	args := &model.User{"小明", 20, 0}
	//调用rpc服务端对象
	//var resp *string
	var resp *model.User
	//1.同步方式调用
	//err = client.Call("Person.GetUser",args, &resp)
	//if err != nil {
	//	//panic(err.Error())
	//	fmt.Println("rpc.DialHTTP.Call 'User.GetUser' error=", err)
	//	return
	//}
	//fmt.Println(*resp)

	//2.异步调用
	//执行返回Call对象，并填充值到syncCall.Done 管道中
	syncCall := client.Go("Person.GetUser",args, &resp, nil)

	replayDone := <-syncCall.Done  //管道取值
	fmt.Println(replayDone)
	fmt.Println(*resp)
}
